package com.ruoyi.back.controller;

import java.util.List;

import com.ruoyi.back.domain.CompanyNews;
import com.ruoyi.back.service.ICompanyNewsService;
import com.ruoyi.common.utils.uuid.SnowflakeIdUtils;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 公司新闻动态Controller
 * 
 * @author luguanqing
 * @date 2021-04-06
 */
@Api(value="公司新闻动态",description = "公司新闻动态接口")
@RestController
@RequestMapping("/back/comnews")
public class CompanyNewsController extends BaseController
{
    @Autowired
    private ICompanyNewsService companyNewsService;

    /**
     * 查询公司新闻动态列表
     */
    //@PreAuthorize("@ss.hasPermi('system:news:list')")
    @ApiOperation(value="公司新闻动态列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "pageNum", value = "页数", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "pageSize", value = "每页记录数", required = true, dataType = "String"),
    })
    @GetMapping("/list")
    public TableDataInfo list(CompanyNews companyNews)
    {
        startPage();
        List<CompanyNews> list = companyNewsService.selectCompanyNewsList(companyNews);
        return getDataTable(list);
    }

    /**
     * 导出公司新闻动态列表
     */
    //@PreAuthorize("@ss.hasPermi('system:news:export')")
    @Log(title = "公司新闻动态", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CompanyNews companyNews)
    {
        List<CompanyNews> list = companyNewsService.selectCompanyNewsList(companyNews);
        ExcelUtil<CompanyNews> util = new ExcelUtil<CompanyNews>(CompanyNews.class);
        return util.exportExcel(list, "news");
    }

    /**
     * 获取公司新闻动态详细信息
     */
    //PreAuthorize("@ss.hasPermi('system:news:query')")
    @ApiOperation(value="获取公司新闻详情")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@ApiParam(name="id",value="公司新闻详情id",required=true)@PathVariable("id") String id)
    {
        return AjaxResult.success(companyNewsService.selectCompanyNewsById(id));
    }

    /**
     * 新增公司新闻动态
     */
    //@PreAuthorize("@ss.hasPermi('system:news:add')")
    @ApiOperation(value="新增公司新闻信息")
    @Log(title = "公司新闻动态", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@ApiParam(name="公司新闻对象",value="传入json格式",required=true)@RequestBody CompanyNews companyNews)
    {
        companyNews.setId(String.valueOf(new SnowflakeIdUtils(0, 0).nextId()));
        return toAjax(companyNewsService.insertCompanyNews(companyNews));
    }

    /**
     * 修改公司新闻动态
     */
    //@PreAuthorize("@ss.hasPermi('system:news:edit')")
    @ApiOperation(value="修改公司新闻信息")
    @Log(title = "公司新闻动态", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@ApiParam(name="公司新闻对象",value="传入json格式",required=true)@RequestBody CompanyNews companyNews)
    {
        return toAjax(companyNewsService.updateCompanyNews(companyNews));
    }


    /**
     * 浏览新闻记录+1
     */
    //@PreAuthorize("@ss.hasPermi('system:information:edit')")
    @ApiOperation(value="浏览新闻记录+1")
    @Log(title = "新闻信息", businessType = BusinessType.UPDATE)
    @GetMapping(value = "/visitUp/{id}")
    public AjaxResult visitUp(@ApiParam(name="id",value="新闻id",required=true)@PathVariable("id") String id)
    {
        return toAjax(companyNewsService.updateVisit(id));
    }


    /**
     * 删除公司新闻动态
     */
    //@PreAuthorize("@ss.hasPermi('system:news:remove')")
    @ApiOperation(value="删除公司新闻信息")
    @Log(title = "公司新闻动态", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@ApiParam(name="id",value="公司新闻id",required=true)@PathVariable String[] ids)
    {
        return toAjax(companyNewsService.deleteCompanyNewsByIds(ids));
    }
}
